<?php

class Eva {
	
	var $config;
	
	var $db = null;
	var $view_dir = 'views/';
	var $output; 
	var $lang = '';
	
	function Eva() {
		$this->config = get_config();	
	}  
	
	/**
	 * 创建数据库连接
	 * @return void
	 */
	function database() {
		$this->db = load_class('DB');
		$this->db->init(
			$this->config['db_username'],	
			$this->config['db_password'],
			$this->config['db_name'],
			$this->config['db_hostname']
		);
	}
	
	/**
	 * 加载库文件
	 * @return void
	 */
	function lib() {
		$lib_list = func_get_args();
		
		foreach( $lib_list as $lib ) {
			$this->$lib = load_class( ucwords($lib) );
		}
	}

	/**
	 * 加载帮助文件
	 * @return unknown_type
	 */
	function helper() {
		$helper_list = func_get_args();
		foreach( $helper_list as $helper  ) {
			require_once( EVAPATH . '/helpers/'. $helper .'_helper.php' );	
		}
	}
	
	/**
	 * 获取配置信息
	 * @param $name
	 * @return string
	 */
	function get_config($name) {
		return isset( $this->config[$name] ) ? $this->config[$name] : null;
	}
	
	function view($viewer, $data=array(), $is_return = FALSE) {
		extract($data);
		ob_start();             
       	include( APPPATH . $this->view_dir . $viewer . '.tpl.php' );  
       	$contents = ob_get_contents();  
       	ob_end_clean();

		if( $is_return ) {
			return $contents;
		}
		else {
			$this->output = $contents;
			return TRUE;
		}
	}
	
	function language($language, $filename) {
		$this->language = $language;
		include( APPPATH . 'language/' . $language . '/' . $filename . '.lang.php' );
		$this->lang = $lang;
	}
	
	function lang( $key ) {
		if( isset( $this->lang[$key] ) ) {
			return $this->lang[$key];
		}
		else {
			return "error"; 
		}
	}
	
	function siteUrl($uri='') {
		if( $this->language == '' ) {
			return base_url() . $this->config['index_page'] . '/' . $uri;
		}
		else {
			return base_url() . $this->config['index_page'] . '/' . $this->language . '/' . $uri;
		}
	}

}


?>